cmake_minimum_required(VERSION 3.18)
project (ResolveDeviceSymbols CUDA)

set(CMAKE_VERBOSE_MAKEFILE ON)
include_directories(include)

add_library(CUDAResolveDeviceDepsA STATIC src/file1.cu)
target_compile_features(CUDAResolveDeviceDepsA PUBLIC cuda_std_11)
set_target_properties(CUDAResolveDeviceDepsA 
                      PROPERTIES
                      CUDA_SEPARABLE_COMPILATION ON
                      POSITION_INDEPENDENT_CODE ON)

add_library(CUDAResolveDeviceLib STATIC src/file2.cu)
set_target_properties(CUDAResolveDeviceLib
                      PROPERTIES
                      CUDA_SEPARABLE_COMPILATION ON
                      CUDA_RESOLVE_DEVICE_SYMBOLS ON
                      POSITION_INDEPENDENT_CODE ON)
target_link_libraries(CUDAResolveDeviceLib PRIVATE CUDAResolveDeviceDepsA)

add_executable(CudaOnlyResolveDeviceSymbols src/main.cu)
set_target_properties(CudaOnlyResolveDeviceSymbols
                      PROPERTIES
                      CUDA_SEPARABLE_COMPILATION OFF
                      CUDA_RESOLVE_DEVICE_SYMBOLS OFF)

target_link_libraries(CudaOnlyResolveDeviceSymbols PRIVATE CUDAResolveDeviceLib)

# if(APPLE)
#   # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
#   set_property(TARGET CudaOnlyResolveDeviceSymbols PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
# endif()
